package com.alm.token.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Html;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alm.token.ConStant;
import com.alm.token.R;
import com.alm.token.base.BaseActivity;
import com.alm.token.ui.data.bean.ActiveMioData;
import com.alm.token.ui.data.bean.ActivityDetailData;
import com.alm.token.ui.data.bean.ActivityIndexData;
import com.alm.token.ui.data.bean.ActivityJoinListData;
import com.alm.token.ui.data.bean.EggRankingData;
import com.alm.token.ui.data.bean.EggWalletLogData;
import com.alm.token.ui.data.bean.RegisterData;
import com.alm.token.ui.data.bean.SuperColorEggData;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.ui.view.ActivityView;
import com.alm.token.ui.view.SuperColorEggView;
import com.alm.token.utils.ActionBarHelper;
import com.alm.token.utils.CommonUtil;
import com.alm.token.utils.DateUtils;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.utils.LogUtil;
import com.alm.token.utils.StringUtils;
import com.bigkoo.pickerview.TimePickerView;

import org.greenrobot.eventbus.EventBus;
import org.web3j.crypto.CipherException;

import java.io.IOException;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import baibeiwallet.event.RefreshActivityEvent;
import baibeiwallet.event.SelWalletEvent;
import baibeiwallet.utils.DialogUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_CODE_VAULE;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_INTO_CODE;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_INTO_CODE1;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_NAME_VAULE;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_SUCC_CODE;

public class ActivityUserInforActivity extends BaseActivity implements ActivityView<Object> {
    @BindView(R.id.leftItem)
    ImageView leftItem;
    @BindView(R.id.centerItem)
    TextView centerItem;

    @BindView(R.id.tv_buycommit)
    TextView tvBuycommit;
    @BindView(R.id.tv_userinfor_country)
    TextView tvUserinforCountry;
    @BindView(R.id.tv_userinfor_city)
    TextView tvUserinforCity;
    @BindView(R.id.tv_userinfor_product)
    TextView tv_userinfor_product;
    @BindView(R.id.tv_userinfor_name1)
    TextView tvUserinforName1;
    @BindView(R.id.tv_userinfor_nameen1)
    TextView tvUserinforNameen1;
    @BindView(R.id.tv_userinfor_name2)
    TextView tvUserinforName2;
    @BindView(R.id.tv_userinfor_nameen2)
    TextView tvUserinforNameen2;
    @BindView(R.id.tv_userinfor_sex)
    TextView tvUserinforSex;
    @BindView(R.id.tv_userinfor_birthplace)
    TextView tvUserinforBirthplace;
    @BindView(R.id.tv_userinfor_passportno)
    TextView tvUserinforPassportno;
    @BindView(R.id.tv_userinfor_birthday)
    TextView tvUserinforBirthday;
    @BindView(R.id.tv_userinfor_passportissueday)
    TextView tvUserinforPassportissueday;
    @BindView(R.id.tv_userinfor_passportexpirydate)
    TextView tvUserinforPassportexpirydate;
    @BindView(R.id.tv_userinfor_passportissuplace)
    TextView tvUserinforPassportissuplace;
    @BindView(R.id.tv_userinfor_phonecode)
    TextView tvUserinforPhonecode;
    @BindView(R.id.tv_userinfor_phone)
    TextView tvUserinforPhone;
    @BindView(R.id.edt_userinfor_remark)
    EditText edtUserinforRemark;

    private String phonecode;

    private ActivityIndexData.DataBean dataBean = new ActivityIndexData.DataBean();
    private List<ActivityDetailData.DataBean.ProductsBean> products = new ArrayList<>();
    private int productId;
    Map<String, String> sexMaps = new HashMap<>();
    List<String> citys = new ArrayList<>();

    @Override
    protected MyPreenter initPreenter() {
        return preenter = new MyPreenter(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_activityuserinfor;
    }

    @Override
    protected void initVariables() {
        dataBean = (ActivityIndexData.DataBean) getIntent().getSerializableExtra("databean");
        products = (List<ActivityDetailData.DataBean.ProductsBean>) getIntent().getSerializableExtra("products");
        productId = getIntent().getIntExtra("selectId", 0);

        for (ActivityDetailData.DataBean.ProductsBean productsBean : products) {
            if (productsBean.getId() == productId) {
                tv_userinfor_product.setText(productsBean.getName());
                break;
            }
        }

        sexMaps.put(getString(R.string.tv_hint_activity_user_man), "0");
        sexMaps.put(getString(R.string.tv_hint_activity_user_woman), "1");

        citys.add(getString(R.string.activity_hint_city1));
        citys.add(getString(R.string.activity_hint_city2));
        citys.add(getString(R.string.activity_hint_city3));
        citys.add(getString(R.string.activity_hint_city4));
        citys.add(getString(R.string.activity_hint_city5));
        initTimePicker();
    }

    @Override
    protected void initViews() {
        new ActionBarHelper(this).setTitle(getString(R.string.tv_hint_activity_userprofile));
    }

    @Override
    protected void loadData() {
    }

    @Override
    public void onClick(View v) {

    }


    @Override
    public void getData(Object o) {

    }

    @Override
    public void getActivityIndexData(ActivityIndexData activityIndexData) {

    }

    @Override
    public void getActivityDetailData(ActivityDetailData activityDetailData) {

    }

    @Override
    public void getActivityJoinData(RegisterData registerData) {


        showToast(registerData.getMsg());
        if (registerData.getStatus() == 0) {
            EventBus.getDefault().post(new RefreshActivityEvent(1));
            Intent intent = new Intent(this, ActivityConfirmationActivity.class);
//            ActivityDetailData.DataBean.UserOrderBean userOrderBean =new ActivityDetailData.DataBean.UserOrderBean();
//            userOrderBean.setId(Integer.valueOf(registerData.getData()));
            intent.putExtra("databean", dataBean);
//                    startActivityForResult(intent);
            startActivity(intent);
            finish();
        }

//        startActivity(ActivityConfirmationActivity.class);
    }

    @Override
    public void getActivityPayOrderData(RegisterData registerData) {

    }

    @Override
    public void getActivityJoinListData(ActivityJoinListData activityJoinListData) {

    }

    @Override
    public void getCode(RegisterData registerData) {

    }

    @Override
    public void jumpToLoginAct(int staue) {
        if (staue == 3) {
//            showToast(getString(R.string.common_relogin));
//            Intent intent = new Intent();
//            intent.setAction(ConStant.EXIT_APP);
//            sendBroadcast(intent);
//            startActivity(BlockWalletLoginActivity.class);
//            finish();
        }else if (staue == 4) {
//            showToast(getString(R.string.paypasw_hint_setpaypsw));
//            Intent intent = new Intent(getActivity(),PayPwdActivity.class);
//            intent.putExtra("PayPwdActivityType",PayPwdActivity.PAYPSW_SET);
//            startActivity(intent);
//            getActivity().finish();
            showToSetPaypswDialog();
        }else if (staue == 666) {
            showToUpdata();
        }
    }

    @Override
    public void onError(String error) {

        showToast(getString(R.string.common_loaderrritry));
    }

    @Override
    public void ShowProgress() {

        showWaitDialog();
    }

    @Override
    public void hideProgress() {

        hideWaitDialog();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.edt_userinfor_remark, R.id.tv_buycommit, R.id.tv_userinfor_country, R.id.tv_userinfor_city, R.id.tv_userinfor_product, R.id.tv_userinfor_name1, R.id.tv_userinfor_nameen1, R.id.tv_userinfor_name2, R.id.tv_userinfor_nameen2, R.id.tv_userinfor_sex, R.id.tv_userinfor_birthplace, R.id.tv_userinfor_passportno, R.id.tv_userinfor_birthday, R.id.tv_userinfor_passportissueday, R.id.tv_userinfor_passportexpirydate, R.id.tv_userinfor_passportissuplace, R.id.tv_userinfor_phonecode, R.id.tv_userinfor_phone})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.edt_userinfor_remark:

                edtUserinforRemark.setFocusable(true);
                edtUserinforRemark.setFocusableInTouchMode(true);
                edtUserinforRemark.requestFocus();
                //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(edtUserinforRemark, 0);

                break;
            case R.id.tv_userinfor_country:
                startActivityForResult(FundArealistActivity.class, INTENT_RESULT_INTO_CODE1);
//                DialogUtils.enterUserinfor(this, tvUserinforCountry.getHint(), (pwd) -> {
//                    tvUserinforCountry.setText(pwd);
//                });
                break;
            case R.id.tv_userinfor_city:
//                showPopupMenu1(tvUserinforCity);
                DialogUtils.enterUserinfor(this, tvUserinforCity.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforCity.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_product:
                if (EmptyUtils.isNotEmpty(products)) {
                    showPopwindow();
                }
                break;
            case R.id.tv_userinfor_name1:
                DialogUtils.enterUserinfor(this, tvUserinforName1.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforName1.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_nameen1:
                DialogUtils.enterUserinfor(this, tvUserinforNameen1.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforNameen1.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_name2:
                DialogUtils.enterUserinfor(this, tvUserinforName2.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforName2.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_nameen2:
                DialogUtils.enterUserinfor(this, tvUserinforNameen2.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforNameen2.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_sex:
                showPopupMenu2(tvUserinforSex);
//                DialogUtils.enterUserinfor(this, tvUserinforSex.getHint(), (pwd) -> {
//                    tvUserinforSex.setText(pwd);
//                });
                break;
            case R.id.tv_userinfor_birthplace:
                DialogUtils.enterUserinfor(this, tvUserinforBirthplace.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforBirthplace.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_passportno:
                DialogUtils.enterUserinfor(this, tvUserinforPassportno.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforPassportno.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_birthday:
                if (EmptyUtils.isNotEmpty(startTimePicker_birthday)) {
                    startTimePicker_birthday.show();
                }
//                DialogUtils.enterUserinfor(this, tvUserinforBirthday.getHint(), (pwd) -> {
//                    tvUserinforBirthday.setText(pwd);
//                });
                break;
            case R.id.tv_userinfor_passportissueday:
                if (EmptyUtils.isNotEmpty(startTimePicker_passissueday)) {
                    startTimePicker_passissueday.show();
                }
//                DialogUtils.enterUserinfor(this, tvUserinforPassportissueday.getHint(), (pwd) -> {
//                    tvUserinforPassportissueday.setText(pwd);
//                });
                break;
            case R.id.tv_userinfor_passportexpirydate:
                if (EmptyUtils.isNotEmpty(startTimePicker_expireday)) {
                    startTimePicker_expireday.show();
                }
//                DialogUtils.enterUserinfor(this, tvUserinforPassportexpirydate.getHint(), (pwd) -> {
//                    tvUserinforPassportexpirydate.setText(pwd);
//                });
                break;
            case R.id.tv_userinfor_passportissuplace:
                DialogUtils.enterUserinfor(this, tvUserinforPassportissuplace.getHint(), InputType.TYPE_CLASS_TEXT, (pwd) -> {
                    tvUserinforPassportissuplace.setText(pwd);
                });
                break;
            case R.id.tv_userinfor_phonecode:
                startActivityForResult(FundArealistActivity.class, INTENT_RESULT_INTO_CODE);
                break;
            case R.id.tv_userinfor_phone:
                DialogUtils.enterUserinfor(this, tvUserinforPhone.getHint(), InputType.TYPE_CLASS_PHONE, (pwd) -> {
                    tvUserinforPhone.setText(pwd);
                });
                break;
            case R.id.tv_buycommit:

                if (verifyData()) {
                    UserWalletData.DataBean.SysMsgBean sysMsgBean = new UserWalletData.DataBean.SysMsgBean();
                    sysMsgBean.setTitle(getString(R.string.common_warmprompt));
                    sysMsgBean.setContent(getString(R.string.tv_hint_activity_user_warm1));
                    DialogUtils.showInfor1(this, sysMsgBean, (pwd) -> {
                        preenter.getActivityJoinData(String.valueOf(dataBean.getId()), edtUserinforRemark.getText().toString(), tvUserinforName2.getText().toString()
                                , tvUserinforNameen2.getText().toString(), phonecode, tvUserinforPhone.getText().toString(), tvUserinforCountry.getText().toString()
                                , sexMaps.get(tvUserinforSex.getText().toString()), tvUserinforBirthplace.getText().toString(), tvUserinforBirthday.getText().toString(),
                                tvUserinforPassportno.getText().toString(), tvUserinforPassportissueday.getText().toString(),
                                tvUserinforPassportexpirydate.getText().toString(), tvUserinforPassportissuplace.getText().toString(),
                                tvUserinforCity.getText().toString(), String.valueOf(productId), tvUserinforName1.getText().toString()
                                , tvUserinforNameen1.getText().toString());
//                        preenter.getEggPartnerAddData(String.valueOf(eggGoodsBeans.get(index).getId()));
                    });
                }

                break;
        }
    }

    private boolean verifyData() {

        if (EmptyUtils.isEmpty(tvUserinforCountry.getText())) {
            showToast(tvUserinforCountry.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforCity.getText())) {
            showToast(tvUserinforCity.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforName1.getText())) {
            showToast(tvUserinforName1.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforNameen1.getText())) {
            showToast(tvUserinforNameen1.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforName2.getText())) {
            showToast(tvUserinforName2.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforNameen2.getText())) {
            showToast(tvUserinforNameen2.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforSex.getText())) {
            showToast(tvUserinforSex.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforBirthplace.getText())) {
            showToast(tvUserinforBirthplace.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforPassportno.getText())) {
            showToast(tvUserinforPassportno.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforBirthday.getText())) {
            showToast(tvUserinforBirthday.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforPassportissueday.getText())) {
            showToast(tvUserinforPassportissueday.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforPassportexpirydate.getText())) {
            showToast(tvUserinforPassportexpirydate.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforPassportissuplace.getText())) {
            showToast(tvUserinforPassportissuplace.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforPhonecode.getText())) {
            showToast(getString(R.string.tv_hint_activity_user_warm2));
            return false;
        }
        if (EmptyUtils.isEmpty(tvUserinforPhone.getText())) {
            showToast(tvUserinforPhone.getHint().toString());
            return false;
        }
        if (EmptyUtils.isEmpty(edtUserinforRemark.getText())) {
            showToast(edtUserinforRemark.getHint().toString());
            return false;
        }
        return true;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == INTENT_RESULT_INTO_CODE && resultCode == INTENT_RESULT_SUCC_CODE && data != null) {
            String name = data.getStringExtra(INTENT_RESULT_NAME_VAULE);
            phonecode = data.getStringExtra(INTENT_RESULT_CODE_VAULE);
            LogUtil.e("name=" + name + "  phonecode=" + phonecode);
            tvUserinforPhonecode.setText("+" + phonecode + "(" + name + ")");
        } else if (requestCode == INTENT_RESULT_INTO_CODE1 && resultCode == INTENT_RESULT_SUCC_CODE && data != null) {
            String name = data.getStringExtra(INTENT_RESULT_NAME_VAULE);
            LogUtil.e("CountryName=" + name);
            tvUserinforCountry.setText(name);
        }
    }


    public void showPopupMenu2(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(this, view);
        //加载menu布局
        Menu menu = popupMenu.getMenu();

        for (String sex : sexMaps.keySet()) {
            menu.add(sex);
        }
        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu, menu);

        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                tvUserinforSex.setText(item.getTitle());
                return true;
            }
        });
        popupMenu.show();
    }

    public void showPopupMenu1(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(this, view);
        //加载menu布局
        Menu menu = popupMenu.getMenu();

        for (String city : citys) {
            menu.add(city);
        }
        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu, menu);

        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                tvUserinforCity.setText(item.getTitle());
                return true;
            }
        });
        popupMenu.show();
    }


    private TimePickerView startTimePicker_birthday, startTimePicker_passissueday, startTimePicker_expireday;

    // 时间选择弹框
    private void initTimePicker() {
        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(DateUtils.getYear() - 100, DateUtils.getMonth(), DateUtils.getDay());
        final Calendar endDate = Calendar.getInstance();
        endDate.set(DateUtils.getYear() + 50, DateUtils.getMonth(), DateUtils.getDay());

        final Calendar endStartDate = Calendar.getInstance();

        //时间选择器
        startTimePicker_birthday = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                String string = StringUtils.cutPreString(DateUtils.format(date, DateUtils.FORMAT_DATE), "-");
                endStartDate.set(Integer.valueOf(string), 0, 1);

                String selectTime = DateUtils.format(date, DateUtils.FORMAT_DATE);
                LogUtil.e(selectTime);
                tvUserinforBirthday.setText(selectTime);
//                pickTime = selectTime;
//                setTextView(tvPick1, selectTime);
//
//
//                getMyWalletRequest(pickTime, pickTypeId + "", pickRole);
            }
        })
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("", "", "", "", "", "") //设置空字符串以隐藏单位提示   hide label
                .setDividerColor(Color.DKGRAY)
                .setContentSize(20)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .isDialog(true)
                .build();
        //时间选择器
        startTimePicker_passissueday = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                String string = StringUtils.cutPreString(DateUtils.format(date, DateUtils.FORMAT_DATE), "-");
                endStartDate.set(Integer.valueOf(string), 0, 1);

                String selectTime = DateUtils.format(date, DateUtils.FORMAT_DATE);
                LogUtil.e(selectTime);
                tvUserinforPassportissueday.setText(selectTime);
//                pickTime = selectTime;
//                setTextView(tvPick1, selectTime);
//
//
//                getMyWalletRequest(pickTime, pickTypeId + "", pickRole);
            }
        })
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("", "", "", "", "", "") //设置空字符串以隐藏单位提示   hide label
                .setDividerColor(Color.DKGRAY)
                .setContentSize(20)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .isDialog(true)
                .build();
        //时间选择器
        startTimePicker_expireday = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                String string = StringUtils.cutPreString(DateUtils.format(date, DateUtils.FORMAT_DATE), "-");
                endStartDate.set(Integer.valueOf(string), 0, 1);

                String selectTime = DateUtils.format(date, DateUtils.FORMAT_DATE);
                LogUtil.e(selectTime);
                tvUserinforPassportexpirydate.setText(selectTime);
//                pickTime = selectTime;
//                setTextView(tvPick1, selectTime);
//
//
//                getMyWalletRequest(pickTime, pickTypeId + "", pickRole);
            }
        })
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("", "", "", "", "", "") //设置空字符串以隐藏单位提示   hide label
                .setDividerColor(Color.DKGRAY)
                .setContentSize(20)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .isDialog(true)
                .build();

        startTimePicker_birthday.setOnDismissListener(new com.bigkoo.pickerview.listener.OnDismissListener() {
            @Override
            public void onDismiss(Object o) {
//                image1Clicked = !image1Clicked;
//                checkImageStatus();
            }
        });
        startTimePicker_passissueday.setOnDismissListener(new com.bigkoo.pickerview.listener.OnDismissListener() {
            @Override
            public void onDismiss(Object o) {
//                image1Clicked = !image1Clicked;
//                checkImageStatus();
            }
        });
        startTimePicker_expireday.setOnDismissListener(new com.bigkoo.pickerview.listener.OnDismissListener() {
            @Override
            public void onDismiss(Object o) {
//                image1Clicked = !image1Clicked;
//                checkImageStatus();
            }
        });
    }

    PopupWindow popWindow;

    private void showPopwindow() {
        View parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
        View popView = View.inflate(this, R.layout.view_pop_selecter, null);
        LinearLayout ly_pop_body = popView.findViewById(R.id.ly_pop_body);

        if (EmptyUtils.isNotEmpty(products)) {
            for (int i = 0; i < products.size(); i++) {
                ActivityDetailData.DataBean.ProductsBean productsBean = products.get(i);

                View itemView = View.inflate(this, R.layout.item_pop_activity_products, null);
//                    GlideApp.with(this)
//                            .load(coinBean.getUrl())
//                            .error(R.drawable.icon_invite_ritht)
//                            .into((ImageView) itemView.findViewById(R.id.img_bizhongicon));
                ((TextView) itemView.findViewById(R.id.title)).setText(productsBean.getName());
                ((TextView) itemView.findViewById(R.id.price)).setText(
                        Html.fromHtml(getString(R.string.hangqing_hint_item_value)
                                + ":" + "<font color=#ff0000>" + "$"
                                + CommonUtil.saveToPoint2WithNo(productsBean.getPrice()) + "</font>"));
                ((TextView) itemView.findViewById(R.id.money)).setText(
                        Html.fromHtml(getString(R.string.easteregg_hint_balance)
                                + ":" + "<font color=#444444>" + ""
                                + productsBean.getNum() + "</font>")
                );
                ((TextView) itemView.findViewById(R.id.desc)).setText(Html.fromHtml(getString(R.string.activity_hint_activity_content)
                        + ":" + "<font color=#444444>" + ""
                        + productsBean.getContent() + "</font>"));
                if (productsBean.getNum() == 0) {
                    itemView.setVisibility(View.GONE);
                }
                int finalI = i;
                itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        bizhongType = finalI;
                        productId = products.get(finalI).getId();
                        tv_userinfor_product.setText(products.get(finalI).getName());

                        popWindow.dismiss();
                    }
                });
                ly_pop_body.addView(itemView);

            }
            ly_pop_body.setBackgroundColor(getResources().getColor(R.color.text_cccccc));
        }

        RelativeLayout outside = popView.findViewById(R.id.pop_outside);

        int width = getResources().getDisplayMetrics().widthPixels;
        int height = getResources().getDisplayMetrics().heightPixels;

        if (popWindow == null) {
            popWindow = new PopupWindow(popView, width, height);
            popWindow.setAnimationStyle(R.style.BottomToTopAnim);
//        popWindow.setFocusable(true);
            popWindow.setOutsideTouchable(true);// 设置同意在外点击消失
        }
        outside.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });

        ColorDrawable dw = new ColorDrawable(0x30000000);
        popWindow.setBackgroundDrawable(dw);
        popWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
}
